/*  
 *  Copyright 2006 Paul Jack.
 *
 *  This file is part of the Dex compiler suite. 
 *  
 *  Dex is free software; you can redistribute it and/or modify it
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 2 of the License, or (at your
 *  option) any later version.
 *  
 *  Dex is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 *  Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 */
package dex.compiler.model.expression;


import java.util.List;

import dex.compiler.model.base.Place;


/**
 * A virtual function call.
 */
public class VirtualCall extends Call {

	
	/**
	 * The object who owns the virtual method.
	 */
	private Expression object;
	
	
	/**
	 * The name of the method being invoked.
	 */
	private String name;
	

	/**
	 * Constructs a new virtual call expression.
	 * 
	 * @param place  the place where the expression originated
	 * @param object  the object who owns the method
	 * @param name   the name of the method to call
	 * @param parameters  the parameters to pass to that function
	 */
	public VirtualCall(Place place, Expression object, String name, List<Expression> parameters) {
		super(place, parameters);
		if (object == null) {
			throw new IllegalArgumentException("object may not be null");
		}
		if (name == null) {
			throw new IllegalArgumentException("name may not be null");
		}
		this.object = object;
		this.name = name;
	}


	@Override
	public String toString() {
		return object + "." + name + "(" + listToString(getParameters()) + ")";
	}
	
	
	/**
	 * Returns the name of the method to call.
	 * 
	 * @return  the function name
	 */
	public String getName() {
		return name;
	}
	
	
	/**
	 * Returns the object.
	 */
	public Expression getObject() {
		return object;
	}

}
